/**
 * Description:
 * Class Name:InetAddressTest
 * Date:2022/5/20 18:37
 *
 * @author LTisme
 * @version JAVA17
 */
package 疯狂Java讲义.第17章_网络编程._17_2_Java的基本网络支持._17_2_1_使用InetAddress;

import java.io.IOException;
import java.net.InetAddress;

public class InetAddressTest {
    public static void main(String[] args) throws IOException {
        String commonWeb = "www.qq.com";
        // 根据主机名来获取对应的InetAddress 实例
        InetAddress ip = InetAddress.getByName(commonWeb);
        // 判断是否可达
        System.out.println(commonWeb + " 域名是否可达：" + ip.isReachable(2000));
        // 获取该InetAddress 实例的IP字符串
        System.out.println(ip.getHostAddress());
        // 根据原始IP地址来获取对应的InetAddress实例
        InetAddress local = InetAddress.getByAddress( new byte[] {127,0,0,1});
        System.out.println("本机是否可达：" + local.isReachable(2000));
        // 获取该InetAddress实例对应的全限定域名
        System.out.println(local.getCanonicalHostName());
    }
}
